# coding:utf-8
import pandas as pd
import numpy as np

# 读取文件
filename = './src/book_data.csv'
data = pd.read_csv(filename, encoding='gbk')

# 统计作品视角
data1 = data['作品视角'].unique()

view = data['作品视角'].value_counts()
view = pd.DataFrame(view)
view = view.reset_index().rename(columns={'index': '作品视角', '作品视角': '数量'})
view.to_excel('./src2/book_view.xlsx', index=False)


# 统计文章类型
# def cut(obj, sec):
#     return [obj[i:i + sec] for i in range(0, len(obj), sec)]
#
#
# type = []
# for i in data['文章类型']:
#     i = i.split("-")
#     for j in i:
#         if len(j) == 4:
#             j = cut(j, 2)
#             for k in j:
#                 type.append(k)
#             continue
#         type.append(j)
# # df1 = Counter(type)
# type = pd.DataFrame(type)
# print(type.value_counts())

# 风格数量
style = data['作品风格'].value_counts()
style = pd.DataFrame(style)
style = style.reset_index().rename(columns={'index': '作品风格', '作品风格': '数量'})
style.to_excel('./src2/book_style.xlsx', index=False)


# 统计文章进度
status = data['文章进度'].value_counts()
status = pd.DataFrame(status)
status = status.reset_index().rename(columns={'index': '文章进度', '文章进度': '数量'})
status.to_excel('./src2/book_progress.xlsx',index=False)

# 作品数量
# data = data['作者'].value_counts()
# data = pd.DataFrame(data)
# data = data.reset_index().rename(columns={'index': '作者', '作者': '作品数量'})
# data.to_excel('./src2/book_count.xlsx', index=False)
